using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI.WebControls;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using AjaxControlToolkit;
using Q.Framework.Data;
using Q.Framework.Utility;
using System.Text;

namespace Q.Framework.WebCode
{
    abstract public class MasterPageBase : MasterPage
    {
        public LogExceptionDelegate ShowException
        {
            get { return Session["ShowException"] as LogExceptionDelegate; }
            set { Session["ShowException"] = value; }
        }

        public virtual void MessageBox(String Message)
        {

            JavaScriptAdd.RegisterStartupScript(this.Page, "Message", new StringBuilder(String.Format("<script>alert('{0}');</script>", Message)));
            //WebCode.MessageBox.Show(Message, WebCode.MessageBox.MessageType.Info);
        }

        public virtual void SetContentFullPage()
        {
        
        }

        public virtual void MessageBoxAndRedirect(String Message, String Url)
        {
            JavaScriptAdd.RegisterStartupScript(this.Page, "Message", new StringBuilder(String.Format("<script>alert('{0}'); window.location.href = '{1}';</script>", Message, Url)));
            //WebCode.MessageBox.Show(Message, WebCode.MessageBox.MessageType.Info, Url);
        }

        private CustomValidator _cv;
        public CustomValidator cv
        {
            get
            {
                if (_cv == null)
                    _cv = new CustomValidator();
                return _cv;
            }
            set { _cv = value; }
        }

        private ModalPopupExtender modalPopup;
        public ModalPopupExtender ModalPopup
        {
            get
            {
                if (modalPopup == null)
                    modalPopup = new ModalPopupExtender();

                return modalPopup;
            }
            set { modalPopup = value; }
        }

        private String messageNewRecord;
        public String MessageNewRecord
        {
            get
            {
                if (String.IsNullOrEmpty(messageNewRecord))
                    if (Page.Request.QueryString.Count > 0)
                        messageNewRecord = "Registro Alterado com Sucesso";
                    else
                        messageNewRecord = "Registro gravado com Sucesso";

                return messageNewRecord;
            }
            set { messageNewRecord = value; }
        }

        private String messageDeleteRecord;
        public String MessageDeleteRecord
        {
            get
            {
                if (String.IsNullOrEmpty(messageDeleteRecord))
                    messageDeleteRecord = "Registro excluido com Sucesso";

                return messageDeleteRecord;
            }
            set { messageDeleteRecord = value; }
        }

        private Boolean displayMessageNewRecording = true;
        public Boolean DisplayMessageNewRecording
        {
            get { return displayMessageNewRecording; }
            set { displayMessageNewRecording = value; }
        }

        private Boolean displayMessageDeleteRecording = true;
        public Boolean DisplayMessageDeleteRecording
        {
            get { return displayMessageDeleteRecording; }
            set { displayMessageDeleteRecording = value; }
        }

        private Boolean displayInformationPage = true;
        public Boolean DisplayInformationPage
        {
            get { return displayInformationPage; }
            set { displayInformationPage = value; }
        }

        private String messageInformationPage;
        public String MessageInformationPage
        {
            get { return messageInformationPage; }
            set { messageInformationPage = value; }
        }

        private Label lblTitle;

        public Label LblTitle
        {
            get { return lblTitle; }
            set { lblTitle = value; }
        }
        private HtmlGenericControl divContainer;

        public HtmlGenericControl DivContainer
        {
            get { return divContainer; }
            set { divContainer = value; }
        }

        private Image imgIcon;
        public Image ImgIcon
        {
            get { return imgIcon; }
            set { imgIcon = value; }
        }

        private Panel pnlVisiblity;
        public Panel PnlVisiblity
        {
            get { return pnlVisiblity; }
            set { pnlVisiblity = value; }
        }

        private Literal ltrErros;
        public Literal LtrErros
        {
            get { return ltrErros; }
            set { ltrErros = value; }
        }

        private Literal ltrDataHora;
        public Literal LtrDataHora
        {
            get { return ltrDataHora; }
            set { ltrDataHora = value; }
        }

        private Label lblErros;
        public Label LblErros
        {
            get { return lblErros; }
            set { lblErros = value; }
        }

        public void AddBlurAtt(Control cntrl)
        {
            if (cntrl.Controls.Count > 0)
            {
                foreach (Control childControl in cntrl.Controls)
                {
                    AddBlurAtt(childControl);
                }
            }

            if (cntrl.GetType() == typeof(TextBox))
            {
                TextBox TempTextBox = (TextBox)cntrl;

                if (TempTextBox.Enabled)
                {
                    TempTextBox.Attributes.Add("onFocus", "DoFocus(this);");
                    TempTextBox.Attributes.Add("onBlur", "DoBlur(this);");
                }
            }
            else if (cntrl.GetType() == typeof(TextBox))
            {
                TextBox TempTextBox = (TextBox)cntrl;

                if (TempTextBox.Enabled)
                {
                    TempTextBox.Attributes.Add("onFocus", "DoFocus(this);");
                    TempTextBox.Attributes.Add("onBlur", "DoBlur(this);");
                }
            }
        }
    }
}